<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>dom操作样式</title>
    <style>
        .div1{
            background: blue;
            width: 200px;
            height: 200px;
        }
    </style>
</head>
<body>
    <div id="div1"></div>
    <button onclick="changeColor()">点我变色</button>
</body>
</html>
<script>
    function changeColor() {
        var div = document.getElementById("div1");
        if (div.className=='div1'){
            div.className='';
        }else {
            div.className = 'div1';
        }
    }
</script>